home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
58189
/
58189.xpi
/
modules
/
PreferenceUtils.jsm
< prev
next >
Wrap
Text File
|
2010-01-06
|
1KB
|
43 lines
/*
* This class provides some utilities to read and write preferences
*/
var EXPORTED_SYMBOLS = [ ];
Components.utils.import("resource://csfiremodules/CsFireCommon.jsm");
CsFire.PreferenceUtils = new function() {};
/*
* Reads a string preference from the filesystem.
*/
CsFire.PreferenceUtils.getStringPreference = function(name, defaultValue) {
var result = defaultValue;
var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
if (prefs.getPrefType(name) == prefs.PREF_STRING) {
try {
result = prefs.getCharPref(name);
}
catch(e) {
CsFire.Logger.warn("Failed to read preference (" + name + "): " + e);
result = defaultValue;
}
}
return result;
}
/*
* Writes a preference to the filesystem
*/
CsFire.PreferenceUtils.setStringPreference = function(name, value) {
var prefservice = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
var prefs = prefservice.getBranch("");
var sString = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
sString.data = value;
try {
prefs.setCharPref(name, sString);
}
catch(e) {
CsFire.Logger.error("Failed to write preference (" + name + "): " + e);
}
}